/**
Classe JS de validation des formulaires
P2011 - Aviaport - GENET LACHICHE MICHEL
BD50
**/

function Validator() {
	this.regEmail = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
	this.regInteger = new RegExp('^[0-9]+$', 'i');
	this.regFloat = new RegExp('^[0-9]+[.]?[0-9]*$', 'i');
	this.regTime = new RegExp('^[0-2][0-9][:][0-5][0-9]$', 'i');
}

Validator.prototype.isEmpty = function(string){
	if(string == 'undefined'
		|| string == ''
	) return true;
	return false;
}

Validator.prototype.stringSizeLimit = function(string, min, max){
	if(string != 'undefined' && typeof(string) == 'string'){
		if(min != 'undefined')
			if(string.length < min) return false;
		if(max != 'undefined')
			if(string.length > max) return false;
		return true;
	}
	return false;
}

Validator.prototype.isEmail = function(string){
	if(string != 'undefined' && typeof(string) == 'string'){
		return this.regEmail.test(string);
	}
	return false;
}

Validator.prototype.isInteger = function(number, min, max){
	if(number != 'undefined'){
		if(this.regInteger.test(number)){
			if(min != 'undefined')
				if(number < min) return false;
			if(max != 'undefined')
				if(number > max) return false;
			return true;
		}
	}
	return false;
}

Validator.prototype.isFloat = function(number, min, max){
	if(number != 'undefined'){
		if(this.regFloat.test(number)){
			if(min != 'undefined')
				if(number < min) return false;
			if(max != 'undefined')
				if(number > max) return false;
			return true;
		}
	}
	return false;
}

Validator.prototype.isTime = function(heure){
	if(heure != 'undefined'){
		return this.regTime.test(heure);
	}
	return false;
}

Validator.prototype.showError = function(idform, namerow, error){
	$("#"+idform+" .row_error_"+namerow).fadeIn();
	$("#"+idform+" .row_error_"+namerow).html(error);
}

Validator.prototype.clearErrors = function(idform){
	$("#"+idform+" .row_error").fadeOut();
}

validator = new Validator();